/*
 * JSudoku.java
 *
 * Created on 2 de Junho de 2007, 15:13
 */

package dharsudoku.gui.sudoku;

/**
 *
 * @author  rodrigo
 */
public class JSudoku extends javax.swing.JFrame {
    
    /**
	 * Creates new form JSudoku
	 */
    public JSudoku() {
	initComponents();
	
	canvasSudoku.addMouseListener((CanvasSudoku)canvasSudoku);
	canvasSudoku.addKeyListener((CanvasSudoku)canvasSudoku);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        canvasSudoku = new CanvasSudoku();
        buttonResolver = new javax.swing.JButton();
        buttonLimpar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Dhar-Sudoku");
        setName("frameSudoku");
        setResizable(false);
        canvasSudoku.setBackground(new java.awt.Color(255, 255, 255));

        buttonResolver.setText("Resolver");
        buttonResolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonResolverActionPerformed(evt);
            }
        });

        buttonLimpar.setText("Limpar");
        buttonLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonLimparActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(canvasSudoku, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(buttonLimpar)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 257, Short.MAX_VALUE)
                        .add(buttonResolver)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(canvasSudoku, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 400, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(buttonResolver)
                    .add(buttonLimpar))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-455)/2, (screenSize.height-486)/2, 455, 486);
    }// </editor-fold>//GEN-END:initComponents

    private void buttonResolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonResolverActionPerformed
	if (!((CanvasSudoku)canvasSudoku).resolver()) {
	    new Aviso(this, true, "Não foi possivel solucionar esta configuração.").setVisible(true);
	}
    }//GEN-LAST:event_buttonResolverActionPerformed

    private void buttonLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonLimparActionPerformed
	((CanvasSudoku)canvasSudoku).zerar();
    }//GEN-LAST:event_buttonLimparActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
	java.awt.EventQueue.invokeLater(new Runnable() {
	    public void run() {
		new JSudoku().setVisible(true);
	    }
	});
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonLimpar;
    private javax.swing.JButton buttonResolver;
    private java.awt.Canvas canvasSudoku;
    // End of variables declaration//GEN-END:variables
    
}
